home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / ASTRONOM / H139.ZIP / RO101.ZIP / RO.H < prev    next >
C/C++ Source or Header  |  1991-11-04  |  15KB  |  372 lines

  1. /********************************************************/
  2. /*                            */
  3. /*    ro.h        General header file for ro    */
  4. /*                            */
  5. /*    ro version 1.10                    */
  6. /*                            */
  7. /*    Portions copyright (c) 1989 by Ted A. Campbell    */
  8. /*        Bywater Software            */
  9. /*        P. O. Box 4023                */
  10. /*        Duke Station                */
  11. /*        Durham, NC  27706            */
  12. /*                            */
  13. /*    Contains portions of ROFF4, Version 1.60    */
  14. /*      (c) 1983, 4 by Ernest E. Bergmann               */
  15. /*        Physics, Building #16            */
  16. /*        Lehigh University            */
  17. /*        Bethlehem, Pa. 18015            */
  18. /*                            */
  19. /*    Contains portions of ROFF4, Version 1.61    */
  20. /*      (c) 1985 by Konrad Kwok                         */
  21. /*        20 3rd Street, Section M        */
  22. /*        Fariview Park,                */
  23. /*        Hong Kong                */
  24. /*                            */
  25. /*    ro and its predecessor ROFF4 are based on     */
  26. /*    the ROFF text processor described in Kernigan    */
  27. /*    and Plauger's now-classic text <Software Tools> */
  28. /*                            */
  29. /* Permission is hereby granted for all commercial and    */
  30. /* non-commercial reproduction and distribution of this */
  31. /* material provided this notice is included.        */
  32. /*                            */
  33. /********************************************************/
  34.  
  35. /************* INCLUDE FILES ****************************/
  36.  
  37. #include "stdio.h"
  38. #include "ctype.h"
  39. #include "time.h"
  40.  
  41. #ifdef __STDC__
  42. #include "stdlib.h"
  43. #include "malloc.h"
  44. #else
  45. #define size_t  int
  46. #define time_t  long
  47. #endif
  48.  
  49. /****** PROGRAM DEFINITIONS *****************************/
  50.  
  51. /***    User-Definable Options ***/
  52.  
  53. #define NONROFF            /* allow non-nroff-standard features */
  54. #define    POSTPROCESS        /* include post-processor */
  55. #define    VERSION        "1.10"    /* current version number */
  56. /* #define    DEBUG    */        /* include debugging routines */
  57.  
  58. /***    End of User-Definable Options ***/
  59.  
  60. #define    ro_    X        /* shorten names for limited compilers */
  61.  
  62. #define MAXLINE 255
  63. #define    PP_STRINGSIZE    64
  64. #define TRUE 1
  65. #define FALSE 0
  66. #define ERROR (-1)
  67. #define OK 0
  68.  
  69. #define    TBUFSIZE    4096    /* Size of temporary holding buffer */
  70. #define BACKSIZE        4096    /* Size of backup buffer */
  71. #define STKSIZ          4
  72. #define HUGE            135     /* generally large number */
  73. #define LSZ             511     /* line buffer size*/
  74. #define COMMAND         '.'     /* all commands starts with this */
  75.  
  76. #define UNKNOWN         -1      /* returned if doesn't recg. command */
  77. #define NO_VAL          -32760  /* returned when no argument w/commad */
  78. #define WE_HAVE_A_WORD   1       /* returned by getwrd func. */
  79. #define NO              0
  80. #define YES             1
  81. #define UNDERLINE       '\137'
  82.  
  83. /***    Character Definitions */
  84.  
  85. #define CR              0x0D
  86. #define BACKSPACE       '\b'
  87. #define BELL        '\007'
  88. #define NUMSIGN         '#'     /* for title strings */
  89. #define NEWLINE         '\n'
  90. #define TAB             '\t'
  91. #define BLANK           ' '
  92. #define FORMF           0x0C    /* formfeed for printer */
  93. #define    ESCAPE        0x1b    /* escape character */
  94. #define SQUOTE          0x27    /* single quote */
  95. #define DQUOTE          0x22    /* double quote */
  96. #define    BACKSLASH    0x5c    /* backslash */
  97. #define    PASSBACK    0xeee    /* a random large number to pass a literal 
  98.                    backslash back into the input stream */
  99.  
  100. /**    Single-character printer code designations ***/
  101.  
  102. #define    ROMAN        'R'    /* Restore "roman" or "regular" font */
  103.                 /* Should turn off Bold and Italic */
  104. #define    ITALIC        'I'    /* Switch to italics or underline */
  105. #define    BOLD        'B'    /* Switch to bold */
  106. #define    HALFUP        'u'    /* Half-line up */
  107. #define    HALFDOWN    'd'    /* Half-line down */
  108.  
  109. #define TRANSLATE     2
  110. #define BLACK         1
  111. #define WHITE         0
  112. #define CONTROL     -1
  113. #define SENTINEL     -2
  114. #define HTAB        -3
  115. #define OTHERS         -4
  116. #define XCHAR         '-'
  117. #define UCHAR         '_'
  118.  
  119. /* defaults for global parameters */
  120.  
  121. #define FI_DEF          1
  122. #define LS_DEF          1
  123. #define IN_DEF          0
  124. #define RM_DEF          70
  125. #define TI_DEF          0
  126. #define CE_DEF          1
  127. #define UL_DEF          -1
  128. #define M1_DEF          2
  129. #define M2_DEF          2
  130. #define M3_DEF          2
  131. #define M4_DEF          2
  132. #define PL_DEF          66
  133. #define FF_DEF          YES     /* .ff defaults to "on" */
  134. #define FF_INI          NO      /* initial setting*/
  135. #define SC_INI          BLANK
  136. #define TS_DEF          8       /*standard tabsize*/
  137. #define TC_DEF          '~'     /*translation flag default*/
  138. #define CF_DEF          '^'     /*Dec 4*/
  139. #define IC_DEF          '\\'
  140. #define CW_DEF          12      /* 12/120" */
  141. #define JU_INI          YES     /* right adjust (justification) */
  142. #define    PO_DEF        0    /* page offset */
  143. #define REGDEF          0       /*default for register var.*/
  144.                                 /*when .rg has no numeric arg*/
  145.  
  146. #define REVSCROLL       FALSE
  147. #define CANBS           FALSE
  148.  
  149. #define FMAX            8       /* # of additional files open*/
  150.  
  151. /* defaults for global parameters */
  152.  
  153. #define FI_DEF          1
  154. #define LS_DEF          1
  155. #define IN_DEF          0
  156. #define RM_DEF          70
  157. #define TI_DEF          0
  158. #define CE_DEF          1
  159. #define UL_DEF          -1
  160. #define M1_DEF          2
  161. #define M2_DEF          2
  162. #define M3_DEF          2
  163. #define M4_DEF          2
  164. #define PL_DEF          66
  165. #define FF_DEF          YES     /* .ff defaults to "on" */
  166. #define FF_INI          NO      /* initial setting*/
  167. #define SC_INI          BLANK
  168. #define TS_DEF          8       /*standard tabsize*/
  169. #define TC_DEF          '~'     /*translation flag default*/
  170. #define CF_DEF          '^'     /*Dec 4*/
  171. #define IC_DEF          '\\'
  172. #define CW_DEF          12      /* 12/120" */
  173. #define JU_INI          YES     /*right justification*/
  174. #define REGDEF          0       /*default for register var.*/
  175.                                 /*when .rg has no numeric arg*/
  176.  
  177. #define REVSCROLL       FALSE
  178. #define CANBS           FALSE
  179.  
  180. #define FMAX            8       /* # of additional files open*/
  181.  
  182. #define FI              1       /* fill lines */
  183. #define TI              2       /* temporary indent */
  184. #define BP              3       /* begin page  */
  185. #define BR              4       /* causes break */
  186. #define CE              5       /* center line(s) */
  187. #define IN              7       /* left indent */
  188. #define LS              8       /* line spacing */
  189. #define NF              9       /* no fill */
  190. #define PL              10      /* set page length */
  191. #define LL              11      /* set line length (right margin) */
  192. #define SP              12      /* add blank line(s) */
  193. #define ST              13      /* stop(pause) at page start?*/
  194. #define FO              14      /* footer title */
  195. #define HE              15      /* header title */
  196. #define M1              16      /* top margin */
  197. #define M2              17      /* second top margin */
  198. #define M3              18      /* first bottom margin */
  199. #define M4              19      /* bottom-most margin       */
  200. #define IG              20      /* "ignore";comments,Nov 6,82*/
  201. #define NE              21      /* "need";Nov 7,82*/
  202. #define FF              22      /* "formfeed";Nov 10*/
  203. #define SC              23      /* "space character";Nov13*/
  204. #define TA              25      /* "tabsize";Nov 13*/
  205. #define EH              26      /* "even headers";Nov 14*/
  206. #define OH              27      /* "odd headers"*/
  207. #define EF              28      /* "even footers"*/
  208. #define OF              29      /* "odd footers"*/
  209. #define EX              30      /* exit ("abort") */
  210. #define DB              31      /* "debug"*/
  211. #define TC              32      /* "translation flag char"*/
  212. #define TR              33      /* "def translation string"*/
  213. #define CF              34      /* Dec 4:control flag char*/
  214. #define IC              35      /* insert character */
  215. #define AD              37      /* adjust (justify) output lines */
  216. #define NA              38      /* no adjust of output lines */
  217. #define WH              39      /* whole line spacing code */
  218. #define FR              40      /* fractional spacing,code */
  219. #define DS              41      /* define string*/
  220. #define DE              42      /* define macro*/
  221. #define EM              43      /* end macro*/
  222. #define NR              44      /* register variable*/
  223. #define DI              45      /* diversion*/
  224. #define SO              47      /* "source", include*/
  225. #define PC              48      /* printer control definition*/
  226. #define TM              49      /* send inline msg to terminal */
  227. #define BJ              50      /* break with right justification
  228.                                    of current line */
  229. #define    PM        51    /* print macro names */
  230. #define    FT        52    /* set font */
  231. #define    PO        53    /* page offset */
  232. #define SS              54      /* show strings */
  233. #define SR              55      /* show registers */
  234.  
  235. /****** GLOBAL VARIABLES ********************************/
  236.  
  237. extern    FILE     *_dobuf, *instream;    /* i/o buffer used for direction  */
  238. #ifdef    DEBUG
  239. extern    int     ro_debug;        /* Boolean:  debug mode on/off */
  240. #endif
  241. extern    int    ro_verbose;        /* Boolean:  verbose mode on/off */
  242. extern    int     ro_pagestop;
  243. extern    int     ro_adjust;
  244. extern    int     ro_useff;
  245. extern    int     ro_firstpage, ro_lastpage;    /* for selectively printing output*/
  246. extern    int     ro_suppress;        /* if true,no output is passed by putchar()*/
  247. extern    int     ro_tival;      /* temporary indent -> default  0 */
  248. extern    int     ro_ceval;      /* set equal to number of lines to be centered  */
  249. extern    int     ro_spval;      /* blank lines to be spaced down */
  250. extern    int     ro_curpag;     /* current output page number; init = 0 */
  251. extern    int     ro_newpag;     /* next output page number; init = 1 */
  252. extern    int     ro_vlineno;    /* virtual (intended) line advances on page,
  253.                         see vadv()*/
  254. extern    int     ro_vflineno;   /* + line fraction */
  255. extern    int     ro_plineno;    /* printer's actual line advances on page,
  256.                         see padv()*/
  257. extern    int     ro_pflineno;   /* + line fraction */
  258. extern    int     ro_bottom;     /* end of text area in lines;start of M3+M4 */
  259. extern    int     ro_sentence;   /* Nov 20*/
  260. extern    int    ro_poval;    /* page offset */
  261.  
  262. /***    Stack variables
  263.  
  264.     The following variables are assigned to a stack and when 
  265.     a new value is assigned, it is "pushed" onto the stack, 
  266.     and when read, "popped" off.  The stack is read from 
  267.     the bottom.                          ***/
  268.  
  269. extern    int     ro_fill[STKSIZ];       /* set to YES or NO  */
  270. extern    int     ro_lsval[STKSIZ];      /* line spacing value -> default will be 1  */
  271. extern    int     ro_inval[STKSIZ];      /* left indent -> default  0  */
  272. extern    int     ro_rmval[STKSIZ];      /* right margin -> default  PAGEWIDTH  */
  273. extern    int     ro_tcval[STKSIZ];      /* translation flag char  */
  274. extern    int     ro_plval[STKSIZ];      /* page length in lines  */
  275. extern    int     ro_m1val[STKSIZ];      /* margin before& including header in lines */
  276. extern    int     ro_m2val[STKSIZ];      /* margin after header in lines */
  277. extern    int     ro_m3val[STKSIZ];      /* margin after last text line in lines */
  278. extern    int     ro_m4val[STKSIZ];      /* bottom margin, including footer in lines */
  279. extern    int     ro_scval[STKSIZ];      /* space character  */
  280. extern    int     ro_tabsiz[STKSIZ];     /* spacing of tabstops  */
  281. extern    int     ro_cfval[STKSIZ];      /* Dec 4:control flag character value  */
  282. extern    int     ro_icval[STKSIZ];      /* insert character */
  283.  
  284. extern    char     ro_curline[ LSZ ];       /*input line buffer, Nov 26 */
  285. extern    char     ro_ehead[ LSZ ], ro_eh2[ LSZ ], ro_eh3[ LSZ ];    /* even header title  */
  286. extern    char     ro_ohead[ LSZ ], ro_oh2[ LSZ ], ro_oh3[ LSZ ];    /* odd header title  */
  287. extern    char     ro_efoot[ LSZ ], ro_ef2[ LSZ ], ro_ef3[ LSZ ];    /* even footer title  */
  288. extern    char     ro_ofoot[ LSZ ], ro_of2[ LSZ ], ro_of3[ LSZ ];    /* even footer title  */
  289.  
  290. struct divfd        /* diversion file descriptor     */
  291.     {
  292.     char nm[ 36 ];    /* name  */
  293.     char fn[ 64 ];    /* name of diversion file (not source file) */
  294.         int cs;        /* character count  */
  295.         int ls;        /* line count  */
  296.     int val;    /* value for register  */
  297.     char *mstr;    /* pointer to macro character string  */
  298.     FILE *bf;    /* to instream if open, FALSE otherwise  */
  299.     struct divfd *prev;
  300.     };
  301.  
  302. extern    char     tbuf[ TBUFSIZE ];    /* a temporary buffer */
  303. extern    int     ro_dir;        /* for "spreading" of lines     */
  304. extern    int     ro_outwrds;    /* no. words in ro_outbuf; init = 0  */
  305. extern    char     ro_outbuf[ LSZ ];     /*lines to be filled collected here  */
  306. extern    int     ro_outw;       /*current display width of ro_outbuf */
  307. extern    int     ro_outpos;     /* =strlen(ro_outbuf)  */
  308. extern    int     ro_wtop, ro_ltop, ro_outtop;   /*zero|negative;levels of subscripts */
  309. extern    int     ro_wbot, ro_lbot, ro_outbot;   /*zero|positive;levels of subscripts */
  310. extern    int     ro_oldln;              /*position of previous main line */
  311. extern    int     ro_oldbot;             /*ro_outbot for previous line;reset
  312.                         each page */
  313. extern    int     ro_frq, ro_frval;  /* fractional line?, what fraction size */
  314. extern    char     *ro_frstring; /* ^ to code for fractional spacing */
  315. extern    char     *ro_whstring; /* ^ to code for whole line spacing */
  316. extern    char     *ro_cptr[128-' '];    /*pointer table for print control */
  317. extern    char     *ro_tptr[128-' '];    /*pointer table for translation strings
  318.                     for char; initialize to null  */
  319.  
  320. extern    struct     divfd *dlink;    /* points to head of diversion list  */
  321. extern    struct     divfd *rlink;    /* points to head of register variable list  */
  322. extern    struct     divfd *slink;    /* points to head of linked string list  */
  323. extern    struct     divfd *mlink;    /* points to head of linked macro list  */
  324.  
  325. /*following added for buffered and formatted output:   */
  326.  
  327. extern    char     ro_out2buf[LSZ];      /*for line to be output in fancy fmt */
  328. extern    int     ro_bpos, ro_cp, ro_pp;         /*buffer,column,printer positions */
  329. extern    char     ro_xbuf[LSZ];         /*strikout buffer */
  330. extern    int     ro_xf, ro_xcol;            /* " flag and column  */
  331. extern    char     ro_ubuf[LSZ];         /*underline buffer */
  332. extern    int     ro_uf, ro_ucol;            /* " flag and column  */
  333. extern    int     ro_first;              /*flag for first pass */
  334. extern    char     ro_dbuf[LSZ];         /*double strike buffer */
  335. extern    int     ro_dpos;
  336. extern    int     ro_ocnt;
  337. extern    int     ro_mcnt;
  338. extern    int     ro_blkcnt;
  339.  
  340. extern    int     ro_newxf, ro_newuf, ro_newmcnt; /* 3rd Mar,85 ; Conrad Kwok  */
  341. extern    char     ro_lastch;    /* 5th Mar,85  ;  Conrad Kwok  */
  342.  
  343. extern    char     ro_backbuf[BACKSIZE];                 /* Backup buffer  */
  344. extern    int     ro_binp;                               /* Position in above;init to 0  */
  345. extern    char     ro_keybd;             /*boolean & prompt for keyboard input */
  346. extern    char     ro_kline[MAXLINE];    /*keyboard line input buffer */
  347. extern    char     *ro_kptr;             /*pointer for above */
  348.  
  349. extern    int         ro_fptr;
  350. extern    FILE     *ro_fstack[FMAX];
  351. extern    int    ro_tflag;/*added for start(), complete() */
  352. extern    int     ro_xf2, ro_uf2, ro_mcnt2;
  353.  
  354. /****** DECLARATIONS FOR EXTERNAL FUNCTIONS ************ */
  355.  
  356. /*      Declarations of externals
  357.  *
  358.  *
  359.  */
  360.  
  361. #ifndef __STDC__
  362. extern  char *malloc();
  363. #endif
  364. extern  char *macq();
  365. extern     struct divfd * find2();
  366. extern  char ro_getch();
  367.  
  368. /******** END OF FILE ***********************************/
  369.  
  370.  
  371.  
  372.